// 初始化段内存
const SEGMENT_ID = 7;
RawMemory.setActiveSegments([SEGMENT_ID]);

// 缓存段内存
let cachedSegment: MapVisionObject = undefined;

/**
 * 获取段内存
 * @returns 段内存表示的对象
 */
export const getSegment = () => {
    if (cachedSegment) {
        return cachedSegment;
    }
    const segment = RawMemory.segments[SEGMENT_ID];
    if (!segment) {
        return {};
    }
    cachedSegment = JSON.parse(segment);
    return cachedSegment;
};

/**
 * 立刻序列化段内存
 */
export const serializeSegment =
    () => RawMemory.segments[SEGMENT_ID] = JSON.stringify(cachedSegment);